<?php

/**
 * @Author: kendy
 * @Date:   2020-01-17 09:27:06
 * @Last Modified by:   jiayanting
 * @Last Modified time: 2020-04-03 16:31:56
 * 商家入驻管理
 */
namespace app\admin\controller;

use think\Db;
use think\View;
use think\Request;
use think\Session;
class Intention extends Common
{
	public function shoplist()
	{
       if (request()->isAjax()){   
            $data = input('param.');
            $page['limit'] = $data['limit'];
            $page['page']  = (int)$data['page'];
            $this->getPageAndSize($page);
            $where = []; 
            if (isset($data['type']) && $data['type'] != ''){
                $where['type'] =  $data['type'];
            }
            if (isset($data['create_time']) && $data['create_time'] != ''){
                $created_at=explode(' - ', $data['create_time']); 
                if (isset($created_at) && is_array($created_at)){
                      $where['create_time']=['between',$created_at]; 
                }
            
            }

            if(isset($data['status']) && $data['status'] != ''){
                $where['status'] =  $data['status'];
            } 
            $count = Db::name("want_apply")->where($where)->count();
            $datas = Db::name("want_apply")->where($where)->order('id desc')->select();
            if(count($datas)>0){
            	foreach ($datas as $key => $value) {
            		if($value['type'] == 1) $datas[$key]['type'] = '景点';
            		if($value['type'] == 2) $datas[$key]['type'] = '酒店';
            		if($value['type'] == 3) $datas[$key]['type'] = '美食';
            		if($value['type'] == 4) $datas[$key]['type'] = '旅行社';
            	}
            }
            ajax_return(config('code.success_show'),'请求成功',$datas,$count); 
        }else{
            return view();
        }		
	}
     /**
      * [dispose 处理意向入驻信息]
      * @Author   kendy
      * @DateTime 2020-01-17T10:09:43+0800
      * @return   [type]                   [description]
      */
	public function dispose(){
        if (request()->isAjax()){
            $postData = input('param.');
            $where = "id = {$postData['id']}";   
            $res =  Db::name("want_apply")->where($where)->update(['status'=>1]);
            if($res){ 
                return 0;
            }else{
                return 1;
            }
        }
	}

}